package cn.com.landsky.alarm.controller;

import cn.com.landsky.alarm.entity.AlarmBox;
import cn.com.landsky.alarm.service.AlarmBoxService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 ** @category 一键呼叫控制器...
 ** @author qing.yunhui
 ** @email: qingyunhui@fentuan360.com
 ** @createTime: 2018/12/25-11:54
 **/
@RestController
@RequestMapping(value="/alarmBox")
@Slf4j
@Api(value = "AlarmBoxController", description = "一键呼叫设备控制器")
public class AlarmBoxController {

    @Autowired
    AlarmBoxService alarmBoxService;

    // ==============================================================> 一键呼叫（设备） ==============================================================>

    @RequestMapping(value="/addBox.htm",method ={RequestMethod.POST})
    @ApiOperation(value = "添加一键呼叫设备")
    public String addBox(AlarmBox alarmBox){
        int count=alarmBoxService.save(alarmBox);
        log.info("=============>调用 add 方法，受影响的行数:{}条。",new Object[]{count});
        return "ok";
    }

    @RequestMapping(value="/deleteBox.htm",method ={RequestMethod.POST})
    @ApiOperation(value = "删除一键呼叫设备")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "java.lang.Long", name = "id", value = "id", required = true)})
    public String deleteBox(Long id){
        int count=alarmBoxService.deleteById(id);
        log.info("=============>调用 delete 方法，受影响的行数:{}条。",new Object[]{count});
        return "ok";
    }

    @RequestMapping(value="/updateBox.htm",method ={RequestMethod.POST})
    @ApiOperation(value = "更新一键呼叫设备")
    @ApiImplicitParams({@ApiImplicitParam(dataType = "java.lang.Long", name = "id", value = "id", required = true)})
    public String updateBox(AlarmBox alarmBox){
        int count=alarmBoxService.update(alarmBox);
        log.info("=============>调用 upadte 方法，受影响的行数:{}条。",new Object[]{count});
        return "ok";
    }

    @RequestMapping(value="/queryBox.htm",method ={RequestMethod.POST})
    @ApiOperation(value = "查询一键呼叫设备")
    public String queryBox(AlarmBox alarmBox){
        List<AlarmBox> cameraList=alarmBoxService.query(alarmBox);
        log.info("=============>调用 query 方法.");
        return JSONObject.toJSONString(cameraList);
    }

}
